package pl.com.qapps.datastore.berkeley;

import java.util.HashMap;
import java.util.Map;

public class Serialization {

	private Serialization() {
	}

	private interface Serializer {

		void parseTo(byte[] buff, int offset, Object value);

		void parseFrom(byte buff, int offset);
	}

	private static final Map<Class<?>, Serializer> serializersMap = new HashMap<>();

	public static void serialize(Object obj, byte[] buff) {
		Serializer s = serializersMap.get(obj.getClass());
		if (s != null) {
			s.parseTo(buff, 0, obj);
		} else
			throw new IllegalArgumentException("Unsupported type: "
					+ obj.getClass());
	}
}
